package grpc

import (
	"context"

	"gitee.com/xgotool/sqlite-logs-more/model"
	"gitee.com/xgotool/sqlite-logs-more/protoc"
	"gitee.com/xgotool/sqlite-logs-more/service/logs"
	"github.com/golang/protobuf/ptypes/empty"
	"google.golang.org/protobuf/types/known/emptypb"
)

// 记录APP端的操作日志
func (c *GrpcRemote) AppLog(cnt context.Context, app *protoc.App) (*empty.Empty, error) {
	der, err := getDid(cnt)
	if err != nil {
		return nil, notFond(err)
	}
	if c.Dervice == nil {
		c.Dervice = der
	}
	pipe_log := model.AppLog{
		Id:      app.Id,
		Did:     der.Id,
		Args:    app.Args,
		File:    app.File,
		Line:    app.Line,
		Level:   app.Level,
		Content: app.Content,
	}
	err = logs.AppLogCreate(&pipe_log)
	if err != nil {
		return nil, sysErr(err)
	}
	return &emptypb.Empty{}, nil
}
